# 作者：陈睿-cruise
# 2024年03月09日19时46分35秒
# 2979386061@qq.com
# 爬取网页基础操作
from selenium import webdriver
from selenium.webdriver.common.by import By

# driver = webdriver.Chrome()
# url = 'https://www.csdn.net/'
# driver.get(url)
# driver.maximize_window()
# 做法一：最后需要close关闭进程
# driver=webdriver.Chrome()
# url='https://top.baidu.com/board?platform=pc&sa=pcindex_entry'
# driver.get(url)
# # 自动导入快捷键：alt+回车
# list_elements=driver.find_elements(By.XPATH,'//div[@class="c-single-text-ellipsis"]')
# for item in list_elements:
#     print(item.text)
#
# driver.close()#释放资源
# 做法二：当程序离开with代码块，python解释器一定释放资源
with webdriver.Chrome() as driver:#创建浏览器
    url='https://top.baidu.com/board?platform=pc&sa=pcindex_entry'
    driver.get(url)#访问页面
    # 自动导入快捷键：alt+回车
    list_elements=driver.find_elements(By.XPATH,'//div[@class="c-single-text-ellipsis"]')
    for item in list_elements:
        print(item.text)
